package com.andyliu.configer;

import com.andyliu.realm.UserRealm;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * ClassName: ShiroConfiger
 * Description: TODO
 * date: 2021/1/21 3:39 下午
 *
 * @author andyliu
 * @since JDK 1.8
 */
@Configuration
public class ShiroConfiger {
    @Bean
    public DefaultWebSecurityManager getSecurityManager(){
        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
        manager.setRealm(this.getUserRealm());
        return manager;
    }
    @Bean
    public Realm getUserRealm(){
        return new UserRealm();
    }
    @Bean("shiroFilter")
    public ShiroFilterFactoryBean getShiroFactoryBean(){
        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
        bean.setSecurityManager(this.getSecurityManager());
        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
        filterChainDefinitionMap.put("/login","anon");
        filterChainDefinitionMap.put("/swagger-ui.html", "anon");
        filterChainDefinitionMap.put("/swagger-resources", "anon");
        filterChainDefinitionMap.put("/swagger-resources/configuration/security", "anon");
        filterChainDefinitionMap.put("/swagger-resources/configuration/ui", "anon");
        filterChainDefinitionMap.put("/v2/api-docs", "anon");
        filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
        filterChainDefinitionMap.put("/sys/**","authc");
        filterChainDefinitionMap.put("/verification","anon");
        filterChainDefinitionMap.put("/doc.html","anon");
        filterChainDefinitionMap.put("/log/**","anon");
        filterChainDefinitionMap.put("/**/*.js","anon");
        filterChainDefinitionMap.put("/**/*.html","anon");
        filterChainDefinitionMap.put("/**/*.png","anon");
        filterChainDefinitionMap.put("/**/*.jpg","anon");
        filterChainDefinitionMap.put("/**/*.css","anon");
        filterChainDefinitionMap.put("/**/*.gif","anon");
        filterChainDefinitionMap.put("/**/*.ico","anon");
        filterChainDefinitionMap.put("/druid/**","anon");
        bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
        return bean ;
    }
}
